import 'package:flutter/material.dart';
import 'package:gold/base/config.dart';
import 'package:gold/ui/my/order/recover/offline_order_page.dart';
import 'package:gold/ui/my/order/recover/online_order_page.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';

/// @description: 黄金回收订单
/// @author tangzhentao
/// @created at 21:02 2024/12/12

class RecoverOrderPage extends StatelessWidget {
  final ValueNotifier<String> _methodNotifier = ValueNotifier(RecoverType.online);

  RecoverOrderPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: xfgAppbar(title: '回收订单'),
      backgroundColor: XfgColor.white,
      body: ValueListenableBuilder<String>(
        valueListenable: _methodNotifier,
        builder: (_, type, __) => Column(
          children: [
            Container(
              height: XfgSize().size34,
              decoration: BoxDecoration(color: XfgColor.colorF2, borderRadius: BorderRadius.circular(XfgSize().size34)),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [_orderMethodWidget('线上', RecoverType.online, type), _orderMethodWidget('线下', RecoverType.offline, type)],
              ),
            ),
            Expanded(
              child: IndexedStack(
                index: type == RecoverType.online ? 0:1,
                children: [
                  OnlineOrderPage(),
                  OfflineOrderPage()
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  /// 订单类型通用布局
  Widget _orderMethodWidget(String text, String index, String select) => GestureDetector(
    onTap: () {
      if (index != select) {
        _methodNotifier.value = index;
      }
    },
    behavior: HitTestBehavior.opaque,
    child: Container(
      width: XfgSize().size95,
      decoration: select == index ? BoxDecoration(color: XfgColor.theme, borderRadius: BorderRadius.circular(XfgSize().size34)):null,
      alignment: Alignment.center,
      child: XfgText(text, fontSize: XfgSize().text16, color: select == index ? XfgColor.white:XfgColor.text1, bold: FontWeight.bold),
    ),
  );
}

